package com.ysz.timewheel.client.conn;

import com.ysz.timewheel.Starter;
import com.ysz.timewheel.client.task.RegisterTask;
import com.ysz.timewheel.server.threadpool.ThreadPool;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

/**
 * @ClassName ClientConn
 * @Description 模拟多客户端连接
 * @Data 16:03
 * @Version 1.0
 * @Author ysz
 */
public class ClientConnect {

    private HashMap<String, Future<Integer>> results = new HashMap<>();

    public void start() {
        this.register();
    }


    public void register() {
        //模拟客户端的连接
        ExecutorService clientService = ThreadPool.clientService;
        for (String ip : Starter.clientsNode) {
            results.put(ip, clientService.submit(new RegisterTask(ip)));
        }
        results.forEach((k, v) -> {
            try {
                System.out.println("ip: " + k + "，收到结果：" + v.get());
            } catch (Exception e) {
            }
        });
    }
}
